show description; allow updating of existing scenarios by URL

Andrew Cantino 10 years ago
parent
commit
bdc5638755

+ 5 - 1
app/controllers/scenario_imports_controller.rb

@@ -1,12 +1,16 @@
1 1
 class ScenarioImportsController < ApplicationController
2 2
   def new
3
-    @scenario_import = ScenarioImport.new
3
+    @scenario_import = ScenarioImport.new(:url => params[:url])
4 4
   end
5 5
 
6 6
   def create
7 7
     @scenario_import = ScenarioImport.new(params[:scenario_import])
8 8
     @scenario_import.set_user(current_user)
9 9
 
10
+    if @scenario_import.will_request_local?(scenarios_url)
11
+      render :text => 'Sorry, you cannot import a Scenario by URL from your own Huginn server.' and return
12
+    end
13
+
10 14
     if @scenario_import.valid?
11 15
       if @scenario_import.do_import?
12 16
         @scenario_import.import!

+ 5 - 1
app/models/scenario_import.rb

@@ -11,8 +11,8 @@ class ScenarioImport
11 11
 
12 12
   attr_reader :user
13 13
 
14
-  before_validation :fetch_url
15 14
   before_validation :parse_file
15
+  before_validation :fetch_url
16 16
 
17 17
   validate :validate_presence_of_file_url_or_data
18 18
   validates_format_of :url, :with => URL_REGEX, :allow_nil => true, :allow_blank => true, :message => "appears to be invalid"
@@ -84,6 +84,10 @@ class ScenarioImport
84 84
     @scenario || @existing_scenario
85 85
   end
86 86
 
87
+  def will_request_local?(url_root)
88
+    data.blank? && file.blank? && url.present? && url.starts_with?(url_root)
89
+  end
90
+
87 91
   protected
88 92
 
89 93
   def parse_file

+ 10 - 3
app/views/scenarios/show.html.erb

@@ -5,6 +5,10 @@
5 5
         <h2><%= "Public" if @scenario.public? %> Scenario <span class='label label-info scenario'><%= @scenario.name %></span></h2>
6 6
       </div>
7 7
 
8
+      <% if @scenario.description.present? %>
9
+        <blockquote><%= @scenario.description %></blockquote>
10
+      <% end %>
11
+
8 12
       <%= render 'agents/table', :returnTo => scenario_path(@scenario) %>
9 13
 
10 14
       <br/>
@@ -12,9 +16,12 @@
12 16
       <div class="btn-group">
13 17
         <%= link_to '<span class="glyphicon glyphicon-chevron-left"></span> Back'.html_safe, scenarios_path, class: "btn btn-default" %>
14 18
         <%= link_to '<span class="glyphicon glyphicon-random"></span> View Diagram'.html_safe, diagram_agents_path(:scenario_id => @scenario.to_param), class: "btn btn-default" %>
15
-        <%= link_to '<span class="glyphicon glyphicon-edit"></span> Edit Scenario'.html_safe, edit_scenario_path(@scenario), class: "btn btn-default" %>
16
-        <%= link_to '<span class="glyphicon glyphicon-share-alt"></span> Share Scenario'.html_safe, share_scenario_path(@scenario), class: "btn btn-default" %>
17
-        <%= link_to '<span class="glyphicon glyphicon-trash"></span> Delete Scenario'.html_safe, scenario_path(@scenario), method: :delete, data: { confirm: "This will remove the '#{@scenario.name}' Scenerio from all Agents and delete it.  Are you sure?" }, class: "btn btn-default" %>
19
+        <%= link_to '<span class="glyphicon glyphicon-edit"></span> Edit'.html_safe, edit_scenario_path(@scenario), class: "btn btn-default" %>
20
+        <% if @scenario.source_url.present? %>
21
+          <%= link_to '<span class="glyphicon glyphicon-plus"></span> Update'.html_safe, new_scenario_imports_path(:url => @scenario.source_url), class: "btn btn-default" %>
22
+        <% end %>
23
+        <%= link_to '<span class="glyphicon glyphicon-share-alt"></span> Share'.html_safe, share_scenario_path(@scenario), class: "btn btn-default" %>
24
+        <%= link_to '<span class="glyphicon glyphicon-trash"></span> Delete'.html_safe, scenario_path(@scenario), method: :delete, data: { confirm: "This will remove the '#{@scenario.name}' Scenerio from all Agents and delete it.  Are you sure?" }, class: "btn btn-default" %>
18 25
       </div>
19 26
     </div>
20 27
   </div>